Repository navigation
Conversation
In RTL, RCTScrollViewComponentView mirrored every scroll view. A vertical one gains nothing from it, and UIKit's views added to the scroll view outside the content view were left mirrored: on iOS 26 the navigation bar's large title is one of them, so it showed up mirrored at the left edge.
6eedd8c to
e29461d
Compare
Abbondanzo
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. Dropping the transform for vertical scroll views is the right approach, but a few places still assume the view is mirrored, which causes three RTL regressions for vertical scroll views:
scrollTo/onScrollxis mirrored when the content is wider than the view. The two RTL conversions still run for every RTL scroll view (see my inline comments below).- The vertical scroll indicator moves from the left to the right and we should make sure this doesn't regress. In RTL, native iOS and Android both put it on the left, so we should ensure we do the same. The inner scroll view is forced to
UISemanticContentAttributeForceLeftToRight, which was only correct while the whole view was mirrored. Also added an inline comment for this one - Vertical scroll views with wider-than-viewport content now open at the RTL end instead of the RTL start. Before this change they started at the right edge, as horizontal scroll views still do, as Android's HorizontalScrollView does in RTL, and as Material's bidirectionality guidance describes for horizontally scrolling content.
The first two are easy to fix with the inline suggests, but the third needs some love. Could you either set the initial offset to the right edge for RTL vertical views that can scroll horizontally, or call out the change in the changelog?
Could you also add XCTest coverage for:
- an RTL horizontal view stays mirrored;
- an RTL vertical view isn't mirrored and gets RTL semantics;
scrollToand the reportedxround-trip correctly in both; and- a recycled view whose horizontal value changed?
If you want a repro for the third issue, here's what I used:
<ScrollView
horizontal={false}
style={{direction: 'rtl', width: 300, height: 60}}
contentContainerStyle={{width: 900, height: 60}}
onScroll={e => console.log(e.nativeEvent.contentOffset.x)}>
{[0, 150, 300, 450, 600, 750].map(x => (
<Text key={x} style={{position: 'absolute', left: x}}>{`|x=${x}`}</Text>
))}
</ScrollView>With this PR, scrollTo({x: 0}) shows the x=600-900 labels while onScroll reports x=0. Before this PR, and in a horizontal scroll view, it shows x=0-300.
There was a problem hiding this comment.
Now that vertical scroll views aren't mirrored, as you alluded to in your PR body, forcing UISemanticContentAttributeForceLeftToRight puts the vertical indicator on the right in RTL (native iOS and Android put it on the left). Giving the scroll view RTL semantics when it's RTL but not mirrored fixes that. A shared _isMirrored also lets the two x conversions below use the same condition:
The comment in RCTEnhancedScrollView's initWithFrame: should then say that left-to-right is the default and only stays forced while the view is mirrored.
| - (BOOL)_isMirrored | |
| { | |
| const auto &scrollViewProps = static_cast<const ScrollViewProps &>(*_props); | |
| return _layoutMetrics.layoutDirection == LayoutDirection::RightToLeft && scrollViewProps.horizontal; | |
| } | |
| - (void)_updateRightToLeftTransform | |
| { | |
| BOOL rtl = _layoutMetrics.layoutDirection == LayoutDirection::RightToLeft; | |
| BOOL mirrored = [self _isMirrored]; | |
| CGAffineTransform transform = mirrored ? CGAffineTransformMakeScale(-1, 1) : CGAffineTransformIdentity; | |
| if (!CGAffineTransformEqualToTransform(_scrollView.transform, transform)) { | |
| _containerView.transform = transform; | |
| _scrollView.transform = transform; | |
| } | |
| _scrollView.semanticContentAttribute = (rtl && !mirrored) ? UISemanticContentAttributeForceRightToLeft | |
| : UISemanticContentAttributeForceLeftToRight; | |
| } |
There was a problem hiding this comment.
Done, applied as suggested. The initWithFrame: comment now says left-to-right is the default and stays forced only while the view is mirrored.
There was a problem hiding this comment.
This flip assumes the scroll view is mirrored, which is now only true for horizontal views. For an RTL vertical view with content wider than the view, onScroll reports the mirrored x.
| if ([self _isMirrored]) { |
There was a problem hiding this comment.
Done, uses _isMirrored now.
There was a problem hiding this comment.
Same here
| if ([self _isMirrored]) { |
There was a problem hiding this comment.
Done, uses _isMirrored now.
A vertical ScrollView in RTL is no longer mirrored, so it now gets RTL semantics (the vertical indicator stays on the left) and the x offset conversions for onScroll and scrollTo run only for mirrored views. Add RCTScrollViewComponentViewRTLTests for mirroring, semantics, the scrollTo/onScroll x round trip and recycled views.
|
Thanks for the thorough review and the repro, that made it easy to see. 1 and 2: I took your suggestions as they are. There is now a shared 3: I went with the changelog option. Setting the initial offset would need extra logic for recycling and for content size changes, and a vertical scroll view whose content is wider than the view is rare, so I'd rather keep this change small. The changelog now says that such a view starts at the left edge in RTL. I added I also ran your repro in RNTester: |
|
Thanks! Could you run the formatter again? I can import after that |
Summary:
In RTL,
RCTScrollViewComponentViewmirrors theUIScrollViewand its content view (scaleX: -1on both), so a horizontal scroll view starts at the right edge while its content still reads correctly.It does this for every scroll view, vertical ones included. A vertical scroll view gains nothing from it, and the two flips cancel out only for the content view. Any view UIKit adds to the scroll view itself stays mirrored once. On iOS 26 the navigation bar's large title is such a view: with a native stack (
headerLargeTitle: true) in an RTL app, the title shows up as a mirrored image at the left edge (screenshot below).This change mirrors only a scroll view whose
horizontalprop is true. The transform is recomputed when the props or the layout direction change, so a recycled view also picks up the right state.Changelog:
[IOS] [FIXED] - In RTL, mirror only horizontal
ScrollViews, so the iOS 26 large navigation title is no longer mirrored[IOS] [CHANGED] - In RTL, a vertical
ScrollViewwhose content is wider than the view now starts at the left edgeTest Plan:
Tested in a production app on React Native 0.88.1 with react-native-screens 4.30.1, on the iOS 26 simulator, with the app in Arabic (
I18nManager.forceRTL(true)).ScrollView: before the change it was mirrored at the left edge. After the change it is right-aligned and reads correctly (screenshot).ScrollViews (a pill tab bar that scrolls the selected pill into view withscrollTo, a segmented row): they still start at the right edge, andscrollTo/onScrolloffsets are unchanged.ScrollView,FlatList): their layout is unchanged.RCTScrollViewComponentViewRTLTestsin RNTesterUnitTests covers a horizontal RTL view staying mirrored, a vertical RTL view not being mirrored and getting RTL semantics,scrollToand the reportedxround-tripping in both, and a recycled view whosehorizontalor layout direction changed.